<template>
  <!--关键岗位信息	-->
  <div>
    <FilterTable
      height="auto"
      ref="tableInfo"

      :columns="columns"
      :isSelectColumn="isSelectColumn"
      selectionType="single"
      :isMemoryPagination="true"
      :onSyncTableData="syncFun"
      :datakey="'records'"
      :isToperInfo="false"
      :onColumnsChange="columns => (this.columns = columns)"
      columnsRef="notification_maintain_info_02">

      <template slot="controls">
        <el-button v-show="formType == 'add' || formType == 'edit'" size="small" type="primary" icon="el-icon-plus" @click="addFun()">新增</el-button>
      </template>
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import * as types from '@/api/cms-api/origin/originInfo/types';
import {phoneAndSolidify,email} from '@/utils/validate.js';
import vm from './bridge';

export default {
  mixins: [dictionary],
  model: {
    prop: 'pdata',
    event: 'click'
  },
  props: {
    pdata: {
      type: Object,
      default: () => ({})
    },
    formType: {
      type: String,
      required: true
    },
    formOptions: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      columns: this.createColumns(),
      isSelectColumn: false,
      saveData: {
        editType: '',
        xxList: []
      },
    };
  },
  mounted() {
    //注册经销商类型变化时触发的事件
  },
  methods: {
    //初始化数据
    init(data) {
      let pdataCopy = JSON.parse(JSON.stringify(this.pdata));
      this.$refs.tableInfo.SET_TABLE_DATA(pdataCopy.logisticsList);
    },
    //表单验证通过后
    formChangeHandle(val) {
      this.pdata = Object.assign(this.pdata, val);
      //传递数据到父组件里
      this.$emit('click', this.pdata);
      //触发外部的事件，以标志着本表单已经准备完毕
      // this.$emit('formchange', this.pdata);
    },
    //开放的提交方法
    saveDialog() {
      let flag = true;
      const err=  this.$refs.tableInfo.GET_REQUIRED_ERROR() // 非空的判断
      const error= this.$refs.tableInfo.GET_FORMAT_ERROR() // 正则的判断
      if(err || error){
        flag = false;
      }
      return flag;
    },
//搜索数据
    createColumns(){
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 50,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button v-show={this.formType == 'add' || this.formType == 'edit'} size="mini" type="text" onClick={() => this.deleteRow(props.row,props.$index)}>
                  删除
                </el-button>
              </div>
            );
          }
        },
        {
          title: '岗位名称',
          dataIndex: 'stationName',
          filterType: 'input',
          sorter: true,
          filter: true,
          editable:true,
          editRequired: this.formType == 'add' || this.formType == 'edit',
          editType: 'select',
          editItems:this.createDictList('1006'),
          dictItems: this.createDictList('1006'),
          // editValidator: (value, row, callback) => {
          //   if (value === undefined || value === '' || value === null) {
          //     callback(new Error("必填字段"));
          //   }
          // }
        },
        {
          title: '姓名',
          dataIndex: 'employeeName',
          filterType: 'input',
          sorter: true,
          editable: true,
          editRequired: true,
          maxlength: 100,
          // editValidator: (value, row, callback) => {
          //   if (value === undefined || value === '' || value === null) {
          //     callback(new Error("必填字段"));
          //   }
          // }
        },
        {
          title: '联系方式',
          dataIndex: 'employeePhone',
          filterType: 'input',
          editRequired: true,
          sorter: true,
          editable: true,
          maxlength: 20,
          // editValidator: phoneAndSolidify,
          // editValidator: (value, row, callback) => {
          //   if (value === undefined || value === '' || value === null) {
          //     callback(new Error("必填字段"));
          //   }
          //   var pattern = /^1[3-9]\d{9}$/;
          //   var solidify = /^(0\d{2,3}\-)?([2-9]\d{6,7})+(\-\d{1,6})?$/;
          //   if (pattern.test(value) || solidify.test(value)) {
          //     callback();
          //   }else{
          //     callback(new Error('请输入正确的手机号或固话'));
          //   }
          // }
        },
        {
          title: '在职状态',
          dataIndex: 'employeeStatus',
          filterType: 'input',
          sorter: true,
          filter: true,
          editable:true,
          editRequired: this.formType == 'add' || this.formType == 'edit',
          editType: 'select',
          editItems:this.createDictList('1008'),
          dictItems: this.createDictList('1008'),
          // editValidator: (value, row, callback) => {
          //   if (value === undefined || value === '' || value === null) {
          //     callback(new Error("必填字段"));
          //   }
          // }
        },
        {
          title: '离职时间',
          dataIndex: 'dimissionDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          showOverflowTooltip: true,
          editable: true,
          editType: 'date-picker',
          dateFormat: 'yyyy-MM-dd HH:mm:ss'
        },
      ];
    },

    deleteRow(row,index) {
      this.$confirm('确认删除', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$refs.tableInfo.EXECUTE_DELETE([row])
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
    },

    syncFun(details){
      this.saveData.xxList = details
    },

    addFun(){
      if(this.saveData.xxList.length == 9){
        this.$notify.warning({title: '提示信息',message:'地址数量已达到上限'});
        return;
      }
      var p = {
        addressType: '',
        address: '',
        linkMan: '',
        linkPhone: '',
        remark: '',
      }
      this.$refs.tableInfo.EXECUTE_INSERT(p)
    },
    //初始化所在市数据
    async initCity(provinceId, row ) {debugger;
      if (!provinceId || provinceId == null || typeof provinceId == 'undefined') {
        return;
      }
      let city = this.initForm.find(item => item.fieldName === 'cityId');
      //清空下级数据
      if (flag) {
        city.initialValue = '';
        let district = this.initForm.find(item => item.fieldName === 'districtId');
        district.initialValue = '';
        district.itemList = [];
      }
      //取省数据
      let rd = this.getRegionData();
      this.cityData = rd[provinceId].children;
      let cl = this.createSubRegionList(this.cityData);
      city.itemList = cl;
    },
  }
};
</script>
